<template>
  <div class="container">
    <el-avatar shape="circle" :size="50" :src="avatar" class="avatar"></el-avatar>
    <span class="nickname">{{name}}</span> 

    <el-button type="primary" @click='logout' style="margin-top:50px;">退出登录</el-button>
  </div>
</template>

<script>
 
export default {
  name:'MainView',
  data(){
    return {
      avatar: require('@/assets/me.jpg')//动态引入需要require
    }
  },
  computed:{
    name(){
      return this.$store.getters.userInfo.nickname;
    }
  },
  methods:{
    logout(){
      localStorage.removeItem('token');
      this.$store.commit('removeUserInfo');
      this.$router.push('/login');
    }
  }
}
</script>

<style lang="scss">
    .container{
        width: 400px;
    }
    .avatar{
      vertical-align: middle;
    }

    .nickname{
      margin-left: 10px;
      font-size: 20px;
    }

</style>